package com.pswv2.util;


import java.util.Date;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;

public class AlipayWithdraw {
	
	private static final String APPID = "2019052965410699";
	private static final String RSA2_PRIVATE = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCcsWvsESEUV3PB/w3So8pxKnS+u0Br5jddoPtnqi8qf+cii/df9aaJIscerM12imp90/pV1Xz3a0qK7wMvM9V4phb6AcRf5tKhHtGFtK7fxXLD4uPlsyyB1rirWzW5UE4Hs6y7mDAamnAqNlGl9LBzPsvSd4SSr3E7b/lk3NtbLgsGonJ9WwxJ/wjwcfe10I6P0HBo7kvYsddd+uBZO0oCSQCiGD96lTjBacG8VZzLO/byxDdJEifBgBbiztI971ku0IiajTUMh+SsdXOp8F7qWI+bKEA6J2YQ5JWWAKpklThCyDinjZVfYqgik8xAP+vVqdj2I7G5LumwUd+Wrc9dAgMBAAECggEAHMbozx4GOTomZEZ3P2wdTdNCRZUWK7rICEX8Zfl3WBLNXCbgc5slzqG4eAW8ZjzdeeZoX0MqBDaMJh/nMdAPMG0wYxHYAtTdcgG68RdR1n7oqNkOiazyS5YnrDDAGRyKeBejbYBxtTEP0HDRZe0eSswJmsmga2AVJ5lU8BUvo/rzL/x19IWp1gVGXLSCHeV+LGPVPPxF84LZw3WNF7MFMMXsxcLOLRo3U6i8fWl3PkTxPWfqlv2Ql230Z13d/2XjBDSr92A2xFIZnxHS3DwGpMMMnUQ6kpFB5p2knXfvcbz8WjzandYtYyX3zJKvWIPGEcTxUkVPWpboY2DxXsO28QKBgQDLnPZFvFMqB+8HbgpsWDOLNyaqhQY1p/RcwRNDbyoQ+XnqxHTS4DBvAxGGlOKy+v2psNI+EpykQGmEOr8eUXD+r+jmC8ByNCSLld2PRLRqKNyNVsI4gYVe2Vb5knaMKRttg2MYb6BiJuLcN/uYh4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HUjTnH2SdqSKOkPeA8/GAZkUcH6KmvlnlIPWHHJFTNcoW/qnD23SHT4413QIDAQAB";
	
	public Integer withdraw(double money,Integer userId,String alipayAccount) {
		String time=new Date().getTime()+"";
		Integer sd = 0;
		String s0=userId+"";
		String s=time.substring(s0.length(), time.length());
		s=s0+s;
		AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APPID, RSA2_PRIVATE, "json", "utf-8",ALIPAY_PUBLIC_KEY, "RSA2");
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        //SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayFundTransToaccountTransferRequest request2 = new AlipayFundTransToaccountTransferRequest();
        request2.setBizContent("{" +
        		"\"out_biz_no\":\""+s+"\"," +
        		"\"payee_type\":\"ALIPAY_LOGONID\"," +
        		"\"payee_account\":\""+alipayAccount+"\"," +
        		"\"amount\":\""+money+"\"," +
        		"\"payer_show_name\":\"样机提现\"," +
        		"\"remark\":\"样机提现\"" +
        		"  }");
	    AlipayFundTransToaccountTransferResponse response2;
	    try {
	    response2 = alipayClient.execute(request2);
	    String endString = response2.getCode();
	        if (endString.equals("10000")) {
	        sd = 1;
	        System.out.println("调用成功");
	        return sd;
	        } else {
	        sd = 0;
	        System.out.println("调用失败");
	        return sd;
	        }
	    } catch (Exception e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		    return sd;
	    }
	}

}
